home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
151-175
/
disk_170
/
fasttext
/
fasttext.doc
< prev
next >
Wrap
Text File
|
1992-05-06
|
9KB
|
280 lines
FastText revision 3.0 Copyright 1988 by Darren M. Greenwald
FastText is a copyrighted program. It may be distributed freely, but it
may NOT be sold/included in any way in any commercial, or shareware
ventures without permission from the author. It may be distributed in
other public domain works so long as a notice of credit appears in the
documentation.
FastText may be distributed as part of a public domain collection, and
posted on telecommunication services so long as no additional charge is
made above, and beyond the normal, and reasonable fees charged for
the media, or use of system time.
If you would like permission to use this program in a commercial, or
shareware venture, I can be contacted via the following methods:
On GEnie: Send E-MAIL to DMG
On Cute (714) 532-5698: Post a message in any forum to Darren Greenwald
At Home: (714) 545-6458
Including FastText in your programs -
FastText is written in assembly using the Manx Assembler. Any changes
needed to assemble this file with other assemblers is left up to you.
You need then only link the resulting object file with your code, and
replace all calls too Text() with FastText(). In addition you must call the
InitFastText() routine before calling FastText(), and finally call
FreeFastText() as part of your cleanup/exit routine(s). See the included
FastText demo (Ftest.c) for an example of how easy this is to use.
In "C" format, the calls are defined like so:
InitFastText
------------
success=InitFastText(Font)
Inputs: Font - pointer to a TextFont structure
Return: TRUE, or FALSE
Description:
This routine does a number of things for you. It checks to make sure that
the font is a non-proportional font; it also checks to make sure the font
is no less then 4 bits wide, but no more then 16 bits. In any other case
this routine returns FALSE. Should this routine fail, you need not concern
yourself too much. In this case all calls to FastText() are automatically
routed to call Text() instead.
Two CHIP RAM buffers are allocated based on the fonts height. Fonts can be
any height, but keep in mind that taller fonts use more memory. One chip
ram buffer is allocated for use as a buffer to draw the text imagery in, and
the other is used to store the unpacked font data.
The font image data buffer requires 512 bytes * the font height.
The drawing buffer requires 128 bytes * the font height.
If this seems like a lot of memory, this is the trade off you make for the
faster text rendering. If the memory cannot be allocated, this routine
will return FALSE, and all calls to FastText() are routed to call Text()
instead.
Finally this routine upacks the font data, sets up the masks, blitter shift
values, and some pointers to the image buffer. Precalculating this
stuff means that these calculations do not have to be done each time a line
of text is rendered.
A special faster blitter routine is used for 8 bit wide fonts because 1.)
Due to the way the blitter handles shifting it is possible to draw 8 bit
wide fonts faster, and 2.) This works out well since 8 bit wide fonts are
commonly used as the system font.
This routine should be called as part of your programs initialization
procedures - it is your option to check for a return value since even if
this fails, all calls to FastText() will automatically call Text() instead.
This routine executes lickety-split; you won't have to wait "a moment" for
the unpacking, and set-up to complete.
FastText
--------
FastText(p,string,length)
Inputs: rp - pointer to a rastport structure
string - pointer to a string
length - length of string to draw
Return: None
Description:
This call is very similar to Text(). It uses the exact same parameters
as Text(), and behaves in a very similar manner. You can set drawing
colors (via SetAPen(), SetBPen()), drawing modes, etc. The text position
is set via the Move() function just like Text().
The X drawing position in the rastport is automatically incremented by the
length (in pixels) of the string of text.
There are also some significant differences (speed of rendering included)!
Unlike Text() which draws a special image for non-defined characters in a
font, FastText() draws undefined characters as blank spaces. This could be
changed if it causes anyone any problems. I prefer it this way, but
perhaps you may not?
FastText() does not currently support any font styles (e.g., bold,
underline, italics). This may be changed in the future.
The REVPATH flag is ignored.
FastText() treats NULL's as End of Line characters regardless of the length
of string parameter. This behavior can be changed if it causes anyone any
problems. I like it this way, but you may not. Yes, this was intentional
since it means I can call FastText(), and set the count to some large
number rather then having to calculate the length of each string. Text()
on the other hand is terminated only by the length parameter, and will
print NULL's as a non-printable character (usually a BOXY looking image).
FreeFastText
------------
FreeFastText()
Inputs: None
Return: None
Description:
Frees memory allocated by InitFastText(). This routine can be called
safely even if InitFastText() failed - in other words, it won't try to free
memory which was never allocated.
----------------------------------------------------------------------
Other notes:
It is very likely that this code is less then perfect. Let the bug reports
roll in! Let me know, and I'll try to fix it ASAP. Also hopefully I can
further optimize the speed of the rendering routines. In the future this
whole thing may change anyway so that multiple fonts can be opened at the
same time.SHAR_EOF
cat << \SHAR_EOF > Ftest.c
/*
* FastText() text demo by Darren M. Greenwald
* Copyright 1987 - FastText() REV 3.0
*
* "C" example of use.
*
* You MUST assemble, and link in the FastText file in order for this to
* work!!!
*
* Note that all work was done using Manx 3.6
* I leave it up to you to make adjustments as needed to work with your
* compiler/assembler.
*
* TURN OFF any text speed up programs if you really want to test this
* program right. Programs such BLITZFONTS, and MicroSmith's FastFonts
* only speed up 8 bit wide fonts. These routines allow you to gain
* a significant speed up for all size fonts, and the most speed up for
* 8 bit wide fonts. Font widths other then 8 bits wide will vary in
* speed. Thinner fonts will be drawn more quickly then wider fonts, but
* you can rest assured that the FastText() routines draw text faster then
* Text() - generally MUCH faster.
*
* If the font cannot be drawn faster (e.g., too wide, too thin, PROP
* font), then Text() is automatically called.
*
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <exec/memory.h>
#define REV 0L
#define SIZE 640L
struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;
struct Window *Window = NULL;
struct RastPort *rp;
struct Window *OpenWindow();
void *OpenLibrary();
struct NewWindow NewWindow =
{ 0,0,640,200,0,1,
CLOSEWINDOW,ACTIVATE|BORDERLESS|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH,
NULL,NULL,
(UBYTE *)"FastText Demo Rev 3.0 - Close me!",
NULL,NULL,0,0,0,0,WBENCHSCREEN
};
void Cleanup();
void main()
{
ULONG MaxRows,fonthght,pixrow,i,j;
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library",REV);
if(IntuitionBase == NULL) Cleanup();
GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library",REV);
if(GfxBase == NULL) Cleanup();
Window = (struct Window *)
OpenWindow(&NewWindow);
if(Window == NULL) Cleanup();
rp = Window->RPort;
/*
* Wait till the close us down cause we are to lazy to mess with gadgets,
* or menus!
*/
Wait(1L<<Window->UserPort->mp_SigBit);
SetAPen(rp,1L);
SetBPen(rp,0L);
InitFastText(rp->Font); /* You could check for a TRUE/FALSE return */
pixrow=32L;
fonthght=(ULONG)rp->Font->tf_YSize;
MaxRows=(Window->Height-pixrow)/fonthght;
SetWindowTitles(Window,"Drawing via Text()",NULL);
for(i=1;i<MaxRows;i++) /* do maximum # of times possible */
{
for(j=1;j<200;j++) /* redraw line 300 times per row */
{
Move(rp,j+4L,pixrow);
Text(rp," This is 36 characters of SLOW text!",36L);
}
pixrow+=fonthght;
}
dox: pixrow=32L;
SetWindowTitles(Window,"Drawing via FastText()",NULL);
for(i=1;i<MaxRows;i++) /* do maximum # of times possible */
{
for(j=1;j<200;j++) /* redraw line 300 times per row */
{
Move(rp,j+4L,pixrow);
FastText(rp," This is 36 characters of FAST text!",36L);
}
pixrow+=fonthght;
}
Cleanup();
}
void Cleanup()
{
FreeFastText();
if(Window) CloseWindow(Window);
if(GfxBase) CloseLibrary(GfxBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
exit(0L);
}